package com.gouaixin.bee.beeframework2.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.gouaixin.bee.beeframework2.R;
import com.gouaixin.bee.beeframework2.bean.ServiceMsg;

import java.util.List;

//聊天消息适配器
public class ServiceMsgAdapter extends BaseAdapter{


	private List<ServiceMsg> lists;

    public List<ServiceMsg> getLists() {
        return lists;
    }

    public void setLists(List<ServiceMsg> lists) {
        this.lists = lists;
    }

    private Context mContext;
	private RelativeLayout layout;
    LayoutInflater inflater;

	public ServiceMsgAdapter(List<ServiceMsg> lists, Context mContext) {
		this.lists = lists;
		this.mContext = mContext;
        this.inflater= LayoutInflater.from(mContext);
	}

    public ServiceMsgAdapter(Context mContext) {
        this.mContext = mContext;
//        this.inflater= LayoutInflater.from(mContext);
    }


    String hericon="";
    String myicon="";
    ImageView icon;
    public void setIcon(String icon){
        this.hericon=icon;
    }
	
	@Override
	public int getCount() {
        if(lists!=null){
            return lists.size();
        }
            return 0;

	}

	@Override
	public Object getItem(int position) {
		return lists.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {

        //如果是接受的消息
		if(lists.get(position).getType() == ServiceMsg.RECEIVER){
			layout = (RelativeLayout) LayoutInflater.from(mContext).inflate(R.layout.item_liaotian_left, null);

            ImageView icon= (ImageView) layout.findViewById(R.id.icon);
            icon.setBackgroundResource(R.drawable.mishu);
		}
        //如果是发送的消息
		if (lists.get(position).getType() == ServiceMsg.SEND) {
			layout = (RelativeLayout) LayoutInflater.from(mContext).inflate(R.layout.item_liaotian_right, null);

            TextView icon= (TextView) layout.findViewById(R.id.icon);
            icon.setBackgroundResource(R.drawable.male_one);


		}
        //设置显示内容
		TextView tv = (TextView) layout.findViewById(R.id.content);
		TextView time = (TextView) layout.findViewById(R.id.time);
		tv.setText(lists.get(position).getMsg());
		time.setText(lists.get(position).getTime());



		return layout;
	}

}
